package cn.htsyb.synergy.security.entity;

import cn.htsyb.synergy.orm.jpa.model.entity.AbsStandardEntity;
import cn.htsyb.synergy.security.constant.DataAuthorizeEL;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.vladmihalcea.hibernate.type.json.JsonType;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.Table;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;
import org.hibernate.annotations.Type;

import java.util.ArrayList;
import java.util.List;
/**
 * @author lakeside hubin_yuan.410@hotmail.com
 * @version V1.0.0
 * @date 2022/5/23
 * @since 1.0
 */
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
@Setter
@Getter
@NoArgsConstructor
@Entity
@DynamicInsert
@Table(name = "security_data_authorize")
@org.hibernate.annotations.Table(appliesTo = "security_data_authorize", comment = "数据授权")
@Schema(description = "用户数据权限")
public class SecurityDataAuthorize extends AbsStandardEntity {
    /**
     * 基于用户的数据权限表达式
     */
    @Column(name = "data_authorize_el", columnDefinition = "TEXT COMMENT '授权指令' ")
    @NotFound(action = NotFoundAction.IGNORE)
    @Schema(name = "dataAuthorizeEL", description = "授权指令")
    DataAuthorizeEL dataAuthorizeEL;
    /**
     * 指定的用户
     */
    @Column(name = "appoint_user", columnDefinition = "TEXT COMMENT '指定用户列表' ")
    @Type(JsonType.class)
    @NotFound(action = NotFoundAction.IGNORE)//允许映射对象为空
    @Schema(name = "appointUserList", description = "指定用户列表")
    List<SecurityUser> appointUserList = new ArrayList<>();
    /**
     * 指定的角色
     */
    @Column(name = "appoint_role", columnDefinition = "TEXT COMMENT '指定角色列表' ")
    @Type(JsonType.class)
    @NotFound(action = NotFoundAction.IGNORE)//允许映射对象为空
    @Schema(name = "appointRoleList", description = "指定角色列表")
    List<SecurityRole> appointRoleList = new ArrayList<>();
    /**
     * 指定的组织
     */
    @Column(name = "appoint_organize", columnDefinition = "TEXT COMMENT '指定组织列表' ")
    @Type(JsonType.class)
    @NotFound(action = NotFoundAction.IGNORE)//允许映射对象为空
    @Schema(name = "appointOrganizeList", description = "指定组织列表")
    List<SecurityOrganize> appointOrganizeList = new ArrayList<>();

}
